#pragma once
#include "vn/FileStream.h"
#include "tests/stub_StreamTest.h"

#include "vn/File.h"

void FileStreamTest_Open() {_test_func_;
	// Open > NotFound
	{
		FileStream a;
		a.Open("_daco.txt", FileMode::Create);
		a.Close();

		File::Delete("_chuaco.txt");

		REQUIRE_EXCEPTION( a.Open("_chuaco.txt", FileMode::Open) );
		REQUIRE_EXCEPTION( a.Open("_chuaco.txt", FileMode::Append) );
		REQUIRE_EXCEPTION( a.Open("_chuaco.txt", FileMode::Truncate) );

		REQUIRE_EXCEPTION( a.Open("_daco.txt", FileMode::CreateNew) );
	}

	FileStream a;

	a.Open("_a.txt", IO::FileMode::Create);
	a.Write("1234567890", 10);
	a.Close();

	a.Open("_a.txt", IO::FileMode::Create);
	a.Write("12345", 5);
	a.Close();

	a.Open("_a.txt", IO::FileMode::Open);
	assert(a.GetLength() == 5);
	a.Close();

	a.Open("_a.txt", IO::FileMode::Append);
	a.Write("12345", 5);
	a.Close();

	a.Open("_a.txt", IO::FileMode::Open);
	assert(a.GetLength() == 10);
	a.Close();

}

void FileStreamTest() {_test_func_;
	FileStreamTest_Open();

	{
		FileStream a;
		a.Open("c:\\file_stream_test.txt", FileMode::Create);
		a.Write("0987654321", 10);
		stub_StreamTest_can(a, true, true, true);
		stub_StreamTest_seek(a);
		stub_StreamTest_read_write(a);
		a.Close();
		stub_StreamTest_exception_if_close(a);
	}

	{
		FileStream a;
		a.Open("test.txt", FileMode::Create);
		a.Write("0123456789", 10);
		a.Write("0123456789", 10);
		a.Seek(-10, SeekEnd);
		a.Write("abcdefghij", 10);
		a.SetLength(14);
		a.Close();
	}
}
